package com.tbit.uqbike.service.business.impl;

import com.tbit.uqbike.object.pojo.WeiXinPushModel;
import com.tbit.common.entity.view.Result;
import com.tbit.uqbike.service.business.WeiXinPushModelService;
import com.tbit.uqbike.webmanager.dao.core.WeiXinPushModelDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 微信小程序服务推送配置实现类
 *
 * @Author:BUGTian
 * @DATE: 2022/7/21
 */
@Service
public class WeiXinPushModelServiceImpl implements WeiXinPushModelService {

    @Autowired
    private WeiXinPushModelDao weiXinPushModelDao;

    @Override
    public Result<WeiXinPushModel> queryWeiXinPushModel(Integer type, Integer accountId) {
        WeiXinPushModel weiXinPushModel = weiXinPushModelDao.queryWeiXinPushModel(type, accountId);
        if (weiXinPushModel == null) {
            //初始化返回值
            weiXinPushModel = new WeiXinPushModel();
            weiXinPushModel.setAccountId(accountId);
            weiXinPushModel.setType(type);
        }
        return Result.success(weiXinPushModel);
    }

    @Override
    public Result editWeiXinPushModel(WeiXinPushModel weiXinPushModel) {
        Integer accountId = weiXinPushModel.getAccountId();
        Integer type = weiXinPushModel.getType();
        if (accountId == null || type == null) {
            return Result.error("参数有误");
        }
        //存在即更新，不存在则插入
        weiXinPushModelDao.replaceWeiXinPushModel(weiXinPushModel);
        return Result.success();
    }
}
